using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 播放或停止实体挂点特效
    /// </summary>
    public class ExecPlayOrStopEntityEffect : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamPlayOrStopEntityEffect;
            if (!config.tagOrMcid.TryGetValue(triggerEntity, out int tagOrMcid))
            {
                LogicLog.LogError("无法获取到tagOrMcid.");
                return;
            }

            List<LevelEntity> entities = ListPool<LevelEntity>.Get();
            {
                if (tagOrMcid == 0)
                {
                    entities.Add(triggerEntity);
                }
                else
                {
                    region.GetEntitiesByTagOrMcid(tagOrMcid, entities);
                }
                //改变属性
                foreach (var entity in entities)
                {
                    entity.ChangeBindEffect(config.effectCid, config.bindPointCid, config.isAdd);
                }
                //通知视图层
                region.NotifyPlayOrStopEntityEffect(player, entities, config.effectCid, config.bindPointCid, config.isAdd);
            }
            ListPool<LevelEntity>.Put(entities);
        }
    }
}
